package gsp420.game;

import java.awt.event.MouseEvent;

/**
 * a basic 2D <u>vector</u> with <b>floating</b> point x/y values
 * similar to the {@link java.awt.Point} class
 * <ul>
 * <li>step 1
 * <li> do the thing
 * <li> omg stop listing stuff
 * </ul>
 * @author Administrator
 *
 */
public class Point
{
	public float x, y;
	
	/** default constructor */
	public Point()
	{
	}
	
	/** copy constructor */
	public Point(Point p)
	{
		set(p);
	}
	
	/** constructor */
	public Point(float x, float y)
	{
		set(x,y);
	}
	/**
	 * mutator. useful when putting a point where a mouse was pressed
	 * sets the {@link #x} and {@link #y} variables
	 */
	public void set(MouseEvent e)
	{
		x = e.getX();
		y = e.getY();
	}
	public void set(Point p)
	{
		x = p.x;
		y = p.y;
	}
	/**
	 * arbitrarily set the position of this {@link Point}
	 * @param a_x
	 * @param a_y
	 */
	public void set(float a_x, float a_y)
	{
		this.x = a_x;
		this.y = a_y;
	}
	
	public void multiply(double value)
	{
		x *= value;
		y *= value;
	}
	
	public void add(Point p)
	{
		x += p.x;
		y += p.y;
	}
	public void subtract(Point p)
	{
		x -= p.x;
		y -= p.y;
	}
	public void setHypotinuse(double h)
	{
		// h^2 = x^2 + y^2
		// h*h = x*x + y*y 
		// h = sqrt(x*x + y*y)
		double currentH = Math.sqrt(x*x+y*y);
		x = (float)(x * h / currentH);
		y = (float)(y * h / currentH);
	}
}
